import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";

const baseRoutes: RouteRecordRaw[] = [
  // 主页
  {
    path: "/",
    name: "Home",
    meta: {
      title: "主页",
    },
    component: () => import("@/views/Home.vue"),
  },
];

// 路由白名单（无需token）
// const ROUTE_WHILE_LIST = [
//   "login",
//   "register",
//   "forgot-password",
//   "401",
//   "404",
//   "500",
// ];

// 动态路由
export const dyRoutes: RouteRecordRaw[] = [
  // vue
  {
    path: "/vue",
    name: "vue",
    meta: {
      title: "vue学习",
    },
    children: [
      {
        path: "/VueMicroFront",
        name: "VueMicroFront",
        meta: {
          title: "vue-微前端",
        },
        children: [
          {
            path: "/MicroFrontReact",
            name: "MicroFrontReact",
            meta: {
              title: "vue-子引用-React",
            },
            component: () =>
              import("@/views/VueStudy/VueMicroFront/MicroFrontReact.vue"),
          },
        ],
      },
      {
        path: "/VueArrow",
        name: "VueArrow",
        meta: {
          title: "vue-箭头函数",
        },
        component: () => import("@/views/VueStudy/arrowFuc.vue"),
      },
      {
        path: "/VueIdRouter",
        name: "VueIdRouter",
        meta: {
          title: "vue-动态传值",
        },
        component: () => import("@/views/VueStudy/VueIdRouter.vue"),
      },
      {
        path: "/fatherSon",
        name: "fatherSon",
        meta: {
          title: "父子通信",
        },
        component: () => import("@/views/VueStudy/fatherSon.vue"),
      },
      {
        path: "/attrs",
        name: "attrs",
        meta: {
          title: "$attrs使用",
        },
        component: () => import("@/views/VueStudy/attrs_father.vue"),
      },
      {
        path: "/shuangXiang",
        name: "shuangXiang",
        meta: {
          title: "vuw2vue3双向绑定",
        },
        component: () => import("@/views/VueStudy/vuw2vue3shaungXiang.vue"),
      },
      {
        path: "/apkAnaly",
        name: "apkAnaly",
        meta: {
          title: "apk包转为zip解析位数",
        },
        component: () => import("@/views/VueStudy/apkAnaly.vue"),
      },
      {
        path: "/watchAndCompute",
        name: "watchAndCompute",
        meta: {
          title: "watch和Compute",
        },
        component: () => import("@/views/VueStudy/watchAndComputed.vue"),
      },
    ],
  },
  // ts
  {
    path: "/ts",
    name: "ts",
    meta: {
      title: "ts学习",
    },
    children: [
      {
        path: "/TsBase",
        name: "TsBase",
        meta: {
          title: "ts基础知识",
        },
        component: () => import("@/views/TsStudy/TsBase.vue"),
      },
    ],
  },
  // css
  {
    path: "/css",
    name: "css",
    meta: {
      title: "css学习",
    },
    children: [
      {
        path: "/CSSBase",
        name: "CSSBase",
        meta: {
          title: "css基础知识",
        },
        component: () => import("@/views/CSSStudy/CSSBase.vue"),
      },
      {
        path: "/CSSLoginCard",
        name: "CSSLoginCard",
        meta: {
          title: "css 卡片框",
        },
        component: () => import("@/views/CSSStudy/CSSLoginCard.vue"),
      },
    ],
  },
  //webpack
  {
    path: "/webpack",
    name: "webpack",
    meta: {
      title: "webpack学习",
    },
    children: [
      {
        path: "/webpackHot",
        name: "webpackHot",
        meta: {
          title: "webpack 热加载",
        },
        component: () => import("@/views/WebpackStudy/webpackHot.vue"),
      },
    ],
  },
  // vite
  {
    path: "/vite",
    name: "vite",
    meta: {
      title: "vite学习",
    },
    children: [
      {
        path: "/viteBase",
        name: "viteBase",
        meta: {
          title: "vite基础知识",
        },
        component: () => import("@/views/ViteStudy/viteBase.vue"),
      },
    ],
  },
  //node
  {
    path: "/node",
    name: "node",
    meta: {
      title: "node学习",
    },
    children: [
      {
        path: "/nodeBase",
        name: "nodeBase",
        meta: {
          title: "node基础知识",
        },
        component: () => import("@/views/NodeStudy/nodeBase.vue"),
      },
    ],
  },
  //性能优化
  {
    path: "/performanceOptinization",
    name: "performanceOptinization",
    meta: {
      title: "性能优化",
    },
    children: [
      {
        path: "/debounceAndThrottle",
        name: "debounceAndThrottle",
        meta: {
          title: "防抖/节流",
        },
        component: () =>
          import(
            "@/views/PerformanceOptinizationStudy/debounceAndThrottle.vue"
          ),
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes: baseRoutes,
});

dyRoutes.forEach((i) => {
  router.addRoute(i);
});

export default router;
